/**
 * 
 */
package cn.mxz.robots.province;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

import cn.mxz.crawler_single.basic.Request;
import cn.mxz.rds.pojo.GaoKaoProvince;
import cn.mxz.rds.pojo.GaoKaoRank;
import cn.mxz.rds.service.GaoKaoProvinceService;
import cn.mxz.rds.service.GaoKaoRankService;
import cn.mxz.robots.basic.local.Exam;
import cn.mxz.robots.basic.local.IRank;
import cn.mxz.robots.pojo.Student;

/**
 * 青海
 * 排名: 完成
 * 去年排名:完成
 * 
 * @author cuizhennan<cuizhennan@mouge.wang>
 * @since 2015-06-19
 */
public class Qinghai extends Exam implements IRank
{

	public Qinghai(Student student)
	{
		super(student);
	}

	@Override
	public String login(String captcha)
	{
		return null;
	}

	@Override
	public String loginParseHtml(String parseHtml)
	{
		return null;
	}

	@Override
	public void initRank()
	{
		// 文 http://www.gxeduw.com/news/2015/125567.html
		// 理 http://www.gxeduw.com/news/2015/125568.html
		Request request = new Request("http://www.gxeduw.com/news/2015/125567.html", mSha1);
		Document result = Jsoup.parse(curlGet(request));

		Elements trs = result.select("table").get(0).select("tr");
		for (int i = 1; i < trs.size(); i++)
		{
			Integer scores = Integer.parseInt(trs.get(i).select("td").get(0).text().replaceAll(" ", ""));
			Integer counters = Integer.parseInt(trs.get(i).select("td").get(1).text());
			Integer rankings = Integer.parseInt(trs.get(i).select("td").get(2).text());
			System.out.println(scores + ":" + counters + ":" + rankings);

			GaoKaoProvinceService provinceService = new GaoKaoProvinceService();
			GaoKaoProvince province = provinceService.get(52);
			GaoKaoRankService rankService = new GaoKaoRankService();
			GaoKaoRank rank = new GaoKaoRank();
			rank.setScore(scores);
			rank.setCount(counters);
			rank.setType(WEN_KE);
			rank.setRanking(rankings);
			rank.setGaoKaoProvince(province);
			rankService.save(rank);
		}
	}

	@Override
	public void lastYearRank()
	{
		// 文 http://www.gxeduw.com/news/2014/108323.html
		// 理 http://www.gxeduw.com/news/2014/108322.html
		Request request = new Request("http://www.gxeduw.com/news/2014/108323.html", mSha1);
		Document result = Jsoup.parse(curlGet(request));

		Elements trs = result.select("table").get(0).select("tr");
		for (int i = 1; i < trs.size(); i++)
		{
			if(trs.get(i).select("td").get(0).text().replaceAll(" ", "").contains("总分"))
				continue;
			
			Integer scores = Integer.parseInt(trs.get(i).select("td").get(0).text().replaceAll(" ", ""));
			Integer counters = Integer.parseInt(trs.get(i).select("td").get(1).text());
			Integer rankings = Integer.parseInt(trs.get(i).select("td").get(2).text());
	
			System.out.println(scores + ":" + counters + ":" + rankings);

			GaoKaoProvinceService provinceService = new GaoKaoProvinceService();
			GaoKaoProvince province = provinceService.get(21);
			GaoKaoRankService rankService = new GaoKaoRankService();
			GaoKaoRank rank = new GaoKaoRank();
			rank.setScore(scores);
			rank.setCount(counters);
			rank.setType(WEN_KE);
			rank.setRanking(rankings);
			rank.setGaoKaoProvince(province);
			rankService.save(rank);
		}

	}
}
